///
if (typeof(popIframe) == 'undefined') {
	popIframe = false;
} else {
	popIframe = true;
}

/**
 * 覆盖
 */
function loadIng() {parent.loadIng();}
function loadEd() {parent.loadEd();}
function loadFix(height) {
	if ( ! popIframe) {
		parent.loadFix(height);
	}
	
	///
	loadEd();
}
function loadUrl(url) {
	if ( ! popIframe) {
		parent.loadUrl(url);
	} else {
		document.location.href = url;
	}
	
	///
	loadIng();
}
function tipMsg(message, type) {parent.tipMsg(message, type);}
function popUrl(url, height, title) {parent.popUrl(url, height, title);}

/**
 * 刷新页面
 */
function refreshPage() {
	if ($("#searchForm").size() != 0) {
		$("#searchForm").submit();
	} else {
		document.location.reload();
	}
}

/**
 * 页面主体资源加载完成
 */
window.onload = function() {
	loadFix();
}

/**
 * 初始化
 */
$(function() {
	/* 普通页面 */
	$("a.AIframe").unbind().click(function() {
		var url = $(this).attr("url");
		
		///
		loadUrl(url);
		return false;
	});
	
	/* ColorBox */
	$("a.popIframe").click(function() {
		var url = $(this).attr("url");
		var height = $(this).attr("vheight");
		var title = $(this).attr("title");
		if (undefined == height) {
			height = 400;
		}
		if (undefined == title) {
			title = "";
		}
		
		///
		popUrl(url, height, title);
		return false;
	});
	
	/* 删除链接 */
	$("a.btnDelete").unbind().click(function() {
		if (confirm("删除无法恢复，是否继续操作？")) {
			var url = $(this).attr("url");
			
			///
			$.ajax({
				type: "POST",
				url: url,
				success: function(data) {
					var message = data;
					var type = 1;
					if (data == "1") {
						refreshPage();
						message = "删除成功";
						type = 0;
					} else if (data == "0") {
						message = "删除失败";
					}
					
					///
					tipMsg(message, type);
				}
			});
			return false;
		}
	});
	
	/* 表单 */
	if ($("#searchForm").size() != 0) {
		// 分页
		$("#page_nav a.AIframe").unbind().click(function() {
			$("#searchForm").attr("action", $(this).attr("url"));
			$("#searchForm").submit();
			
			///
			loadIng();
			return false;
		});
		
		// 搜索
		$("#searchForm").validate({
			submitHandler: function(form) {
				form.submit();
				
				///
				loadIng();
				return false;
			}
		});
	}
	
	/* 列表 */
	if ($(".list-div").size() != 0) {
		$(".list-div table tr").hover(function() {
			$(this).addClass("on");
		}, function() {
			$(this).removeClass("on");
		});
	}
});
